package com.cltech.mapper;

import com.cltech.dto.SysPermissionDto;
import com.cltech.dto.TreeNode;
import com.cltech.entity.sys.SysPermission;
import org.mapstruct.*;
import org.springframework.data.domain.Page;

import java.util.List;

/**
 * Created by Administrator on 2019/4/14.
 */
@Mapper(componentModel = "spring")
public interface SysPermissionMapper {
    @Mappings({
            @Mapping(source = "parentId", target = "parent.id"),
            @Mapping(source = "parentName", target = "parent.name"),
            @Mapping(source = "parentLink", target = "parent.link"),
            @Mapping(source = "parentType", target = "parent.type"),
            @Mapping(source = "parentPermissionCode", target = "parent.permissionCode")
    })
    SysPermission dtoToEntity(SysPermissionDto sysRoleDto);
    @InheritConfiguration(name ="dtoToEntity")
    List<SysPermission> dtoToEntity(List<SysPermissionDto> sysRoleDto);
    @InheritInverseConfiguration(name ="dtoToEntity")
    SysPermissionDto entityToDto(SysPermission sysRole);
    @InheritInverseConfiguration(name ="dtoToEntity")
    List<SysPermissionDto> entityToDto(List<SysPermission> sysRole);
    default Page<SysPermissionDto> entityToDto(Page<SysPermission> page){
        return page.map(this::entityToDto);
    }
    @Mappings({
            @Mapping(source = "id", target = "key"),
            @Mapping(source = "parent.id", target = "pid"),
            @Mapping(source = "name", target = "title"),
            @Mapping(source = "permissionCode", target = "code"),
            @Mapping(source = "type", target = "type"),
            @Mapping(source = "link", target = "link"),
            @Mapping(source = "icon", target = "icon"),
            @Mapping(source = "children",target = "children",ignore = true)
    })
    TreeNode entityToTreeNode(SysPermission sysPermission);
    @InheritConfiguration(name ="entityToTreeNode")
    List<TreeNode> entityToTreeNode(List<SysPermission> sysPermission);
}